import java.util.Scanner;

public class ArrayAdd {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("是否要添加数组元素：y/n");
            String choose = scanner.next();
            if (choose.equals("y")) {
                System.out.println("请输入要添加的元素：");
                int element = scanner.nextInt();
                int[] arrNew = new int[arr.length + 1];
                for (int i = 0; i < arr.length; i++) {
                    arrNew[i] = arr[i];
                }
                arrNew[arr.length] = element;
                arr = arrNew;
                System.out.println("添加完的数组为：");
                for (int i = 0; i < arr.length; i++) {
                    System.out.println(arr[i]);
                }
            } else {
                System.out.println("程序退出！");
                return;
            }
        }
    }
}
